package org.aeon.client.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.client.context.GlobalContext;
import org.aeon.client.context.MessageMap;
import org.aeon.message.response.SearchResponseMessage;

import static org.aeon.client.context.MessageMap.MessageContextKey.SearchGroupList;
import static org.aeon.client.context.MessageMap.MessageContextKey.SearchUserList;


/**
 * @author: MissingAeon
 * @date: 2024/2/22 20:12
 * @description:
 */
@Slf4j
@ChannelHandler.Sharable
public class SearchResponseHandler extends SimpleChannelInboundHandler<SearchResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, SearchResponseMessage msg) throws Exception {
        final MessageMap messageMap = GlobalContext.getContext().getMessageMap();
        messageMap.set(SearchUserList, msg.getUsers());
        messageMap.set(SearchGroupList, msg.getGroups());
        ctx.fireChannelRead(msg);
    }
}
